package 抽象工厂模式;
import java.util.Scanner;

/*
 * 抽象工厂模式提供一个接口，用于创建相关或者依赖对象的家族，而不需要明确指定具体类。

        抽象工厂允许客户端使用抽象的接口来创建一组相关的产品，而不需要关系实际产出的具体产品是什么。这样一来，客户就可以从具体的产品中被解耦。
 */
public class Main {

	public static void main(String[] args) {
		//1.接受控制台输入
		System.out.println("---计算器---");
		System.out.println("请输入第一个数：");
		Scanner sc = new Scanner(System.in);
		String number1 = sc.nextLine();
		
		System.out.println("请输入运算符：");
		String oper = sc.nextLine();
		
		System.out.println("请输入第二个数：");
		String number2 = sc.nextLine();
		double result = 0;
		double num1 = Double.parseDouble(number1);
		double num2 = Double.parseDouble(number2);
		OperationFactory factory = null;
		//2.进行运算
		if("+".equals(oper)){
			factory = new AddOperationFactory(); 
		}else if("-".equals(oper)){
			factory = new SubOperationFactory(); 
		}else if("*".equals(oper)){
			factory = new MulOperationFactory(); 
		}else if("/".equals(oper)){
			factory = new DivOperationFactory(); 
		}
		Operation operation = factory.getOperation();
		operation.setNumber1(num1);
		operation.setNumber2(num2);
		result = operation.getResult();
		//3.打印结果
		System.out.println("运算结果为：");
		System.out.println(number1 + oper + number2 +"="+result);
	}

}
